#pragma once
#include <ctemplate/template.h>
#include <iostream>
#include <string>

#include "model.hpp"

namespace wjh_view
{
    using namespace wjh_model;

    const std::string Template_Path = "./Template_Html/";

    class View
    {
    public:
        //构建一个有全部题目列表的html, output输出型参数
        bool AllExpandHtml(const std::vector<Question>& QuestionsList, std::string& output)
        {
            std::string path = Template_Path + "allQuestions.html";
            ctemplate::TemplateDictionary root("allQuestions");

            for(const auto& e : QuestionsList)
            {
                ctemplate::TemplateDictionary* sub = root.AddSectionDictionary("questions_list");
                sub->SetValue("number", e.number);
                sub->SetValue("name", e.name);
                sub->SetValue("star", e.star);
            }

            ctemplate::Template* tpl = ctemplate::Template::GetTemplate(path, ctemplate::DO_NOT_STRIP);
            tpl->Expand(&output, &root);
            return true;
        }

        //构建一个有指定题目的html, output输出型参数
        bool OneExpandHtml(const Question& question, std::string& output)
        {
            std::string path = Template_Path + "oneQuestion.html";
            ctemplate::TemplateDictionary root("oneQuestion");
            root.SetValue("number", question.number);
            root.SetValue("title", question.name);
            root.SetValue("star", question.star);
            root.SetValue("desc", question.desc);
            root.SetValue("pre_code", question.header);

            ctemplate::Template* tpl = ctemplate::Template::GetTemplate(path, ctemplate::DO_NOT_STRIP);
            tpl->Expand(&output, &root);
            return true;
        }
    };

}


